#include "mainwindow.h"
#include <QMenuBar>
#include <QMenu>
#include <QAction>

#include <QString>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->setWindowTitle("记事本");
    this->resize(600, 400);
    QMenuBar* menuBar = new QMenuBar;
    this->setMenuBar(menuBar);

    QMenu* fileMenu = menuBar->addMenu("文件");
    QMenu* editMenu = menuBar->addMenu("编辑");
    QMenu* formatMenu = menuBar->addMenu("格式");
    QMenu* checkMenu = menuBar->addMenu("查看");
    QMenu* helpMenu = menuBar->addMenu("帮助");

    fileMenu->addAction("新建");
    fileMenu->addAction("打开");
    fileMenu->addAction("保存");
    fileMenu->addAction("另存为");
    fileMenu->addSeparator();
    QAction* exitAction = fileMenu->addAction("退出");
    connect(exitAction, &QAction::triggered, this, &QMainWindow::close);

    editMenu->addAction("撤销");
    editMenu->addSeparator();
    editMenu->addAction("复制");
    editMenu->addAction("剪切");
    editMenu->addAction("粘贴");

    formatMenu->addAction("自动换行");
    formatMenu->addAction("字体");

    QMenu* zoomMenu = checkMenu->addMenu("缩放");
    checkMenu->addAction("状态栏");
    checkMenu->addAction("自动换行");
    zoomMenu->addAction("放大");
    zoomMenu->addAction("缩小");
    zoomMenu->addAction("还原默认缩放");

    helpMenu->addAction("帮助文档");
    helpMenu->addAction("关于我们");

    QString filePath = "e:/work/c++/main.cpp";
    QMap<QString, QString> result = this->dealPath(filePath);
    for (auto it = result.begin(); it != result.end(); it++)
    {
        qDebug() << it.key() << it.value();
    }
}

QMap<QString, QString> MainWindow::dealPath(QString filePath)
{
    filePath = filePath.trimmed();
    QMap<QString, QString> result;
    QStringList splitList = filePath.split("/");
    QString filename = splitList[splitList.size() - 1];
    QString pureFilename = splitList[splitList.size() - 1].split(".")[0];
    QString fileSuffix = filePath.split(".")[1];
    QString absolutePath = filePath.section("/", 0, filePath.count("/") - 1);
    result["filename"] = filename;
    result["pureFilename"] = pureFilename;
    result["fileSuffix"] = fileSuffix;
    result["absolutePath"] = absolutePath;

    return result;
}


MainWindow::~MainWindow()
{

}
